<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="root">
        //加冒号是数字,不加冒号是字符串
        <counter v-bind:count="0" @change="handleIncrease"></counter>
        <counter v-bind:count="1" @change="handleIncrease"></counter>
        <div>{{total}}</div>
    </div>
<!--    单向数据流:子组件不建议给父组件传的参数进行修改-->
    <script>
        var counter = {
            props:['count'],
            // 更改克隆副本
            data:function(){
                return{
                    number: this.count
                }
            },
            template:'<div @click="handleClick">{{number}}</div>',
            methods:{
                handleClick:function () {
                    this.number ++;
                    this.$emit("change",1)
                }
            }
        };

        var vm = new Vue({
            el:"#root",
            data:{
                total: 1,
            },
            //注册局部组件
            components:{
                counter:counter,
            },
            methods:{
                handleIncrease:function (step) {
                    this.total += step
                }
            }
        })
    </script>

</body>
</html>
